/* 
 * File:   Trapezium.cpp
 * Author: lgr013
 * 
 * Created on 13 de septiembre de 2014, 12:12
 */

#include "Trapezium.h"

Trapezium::Trapezium() {
}

Trapezium::Trapezium(ObjFactory *objFactory, bool flagStatic, float x, float y, float base, float height, double alpha, double beta, float mass, float rotation) {
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    if (height < 0 || base < 0) {
        myLogFile->writeInLog(2, "[2] Tamaño del trapecio invalido (Base o altura negativo)\n");
    }

    Dot *dot = new Dot(x, y, base, height);
    this->dot = dot;

    Object *object = objFactory->getObjectTrapezium(flagStatic, dot->dotPixelsToWorld(), dot->sizeDotPixelsToWorld(), alpha, beta, mass, rotation);
    this->object = object;
    this->alpha = alpha; // radianes
    this->beta = beta; //radianes

    myLogFile->writeInLog(0, "[0] Se ha creado un trapecio exitosamente\n");
}

Trapezium::~Trapezium() {
    delete this->dot;
    delete this->object;

//    printf("destructor trapecio \n");
}

bool Trapezium::draw(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
    SBSLog* myLogFile;
    myLogFile->getInstance(MY_LOG_MODE);

    bool success = true;
    Object *obj = this->object;

    float posX = obj->getBody()->GetPosition().x;
    float posY = obj->getBody()->GetPosition().y;

    this->dot->setPos(posX, posY);

    success = obj->getSkin()->makeTrapezium(this->dot->dotWorldToPixels(), this->dot->sizeDotWorldToPixels(), this->alpha, this->beta, this->getAngle(), r, g, b, a);

    if (!success) {
        myLogFile->writeInLog(2, "[2] Ha ocurrido un error mientras se intentaba dibujar el rectangulo\n");
    }

    return success;
}

b2Vec2 Trapezium::getPosition() {
    return this->object->getPosition();
}

float Trapezium::getAngle() {
    return this->object->getAngle();
}

float Trapezium::getAngularVelocity() {
    return this->object->getAngularVelocity();
}

void Trapezium::setAngularVelocity(float velocity) {
    this->object->setAngularVelocity(velocity);
}
